package com.aqielife.demo.example.lambda;

public class LambdaDemo {
    @FunctionalInterface
    interface Interface1 {
        int doubleNum(int i);       // 返回类型int 输入也是int的doubleNum方法

        default int add(int x, int y) {
            x = this.doubleNum(x);
            return x + y;
        }

        static int sub(int x, int y) {
            return x - y;
        }
    }

    @FunctionalInterface
    interface Interface2 {
        int doubleNum(int i);

        default int add(int x, int y) {
            return x + y;
        }
    }

    @FunctionalInterface
    interface Interface3 extends Interface2, Interface1 {
        @Override
        default int add(int x, int y) {
            return Interface1.super.add(x, y);
        }
    }

    public static void main(String[] args) {
        // 实现接口方法
        Interface1 i1 = (i) -> i * 2;
        // 调用接口默认方法
        System.out.println(i1.add(2,3));
        System.out.println(i1.doubleNum(7));

        // 最常见写法
        Interface1 i2 = i -> i * 3;

        Interface1 i3 = (int i) -> i * 2;

        Interface1 i4 = (int i) -> {
            System.out.println("---");
            return i * 2;
        };
    }
}
